package Test;

public class test2 {
    //力扣 1089 复写零
    //注释就不写了，再画个图好好理解一下
    public static void main(String[] args) {
        int[] arr = {1,0,2,0,4,0,2};
        int cur = 0;
        int dest = -1;
        while(cur<arr.length){
            if(arr[cur]!=0){
                dest++;
            }else {
                dest+=2;
            }
            if(dest>=arr.length-1){
                break;
            }
            cur++;
        }
        System.out.println(cur);
        System.out.println(dest);
        if(dest==arr.length){
            arr[dest-1]=0;
            cur--;
            dest-=2;
        }
        while(cur>=0){
            if(arr[cur]!=0){
                arr[dest] = arr[cur];
                dest--;
                cur--;
            }else{
                arr[dest] = 0;
                arr[dest-1] = 0;
                cur--;
                dest-=2;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }

    }
}
